package com.zhihu_lvliangi_android.option.yiliao;

import java.util.ArrayList;
import java.util.List;

import com.android.widget.listview.pullload.PullLoadListView;
import com.zhihu_lvliangi_android.R;
import com.zhihu_lvliangi_android.R.id;
import com.zhihu_lvliangi_android.R.layout;
import com.zhihu_lvliangi_android.R.menu;
import com.zhihu_lvliangi_android.domain.CureRecord;
import com.zhihu_lvliangi_android.domain.CureRecord.Cure;
import com.zhihu_lvliangi_android.domain.HospitalRecord;
import com.zhihu_lvliangi_android.domain.PlanModel;
import com.zhihu_lvliangi_android.option.parent.ParentActivity;
import com.zhihu_lvliangi_android.option.yiliao.adapter.CureRecordAndHospitalAdapter;
import com.zhihu_lvliangi_android.option.zhengwu.EvaluateDetailActivity;
import com.zhihu_lvliangi_android.option.zhengwu.GuideEvaluateActivity;
import com.zhihu_lvliangi_android.option.zhengwu.adapter.EvluateListViewAdapter;
import com.zhihu_lvliangi_android.util.Constant;

import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;

public class CureRecordActivity extends ParentActivity {

	private PullLoadListView mPullListView;
	private List mRecords = new ArrayList();;//两种数据格式 ,应该考虑抽取基类
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		int id = item.getItemId();
		if (id == android.R.id.home) {
			finish();
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	private void initActionBar() {
		ActionBar actionBar = getSupportActionBar();
		actionBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.action_bar));
		actionBar.setDisplayHomeAsUpEnabled(true);
		actionBar.setIcon(new BitmapDrawable());//不设置图标icon
	}

	@Override
	protected int getLayoutId() {
		return R.layout.activity_guide_progress;
	}



	@Override
	protected void setupViews() {
		initActionBar();
		CureRecord record = new CureRecord();
		
		record = new CureRecord();
		record.setPatient_name("张钧");
		record.setCure_type("心血管内科");
		record.setDate("2014/12/1");
		record.setHospital("吕梁市人民医院");
		record.setReult("冠心病");
		record.setFee("27.3");
		mRecords.add(record);
		
		record = new CureRecord();
		record.setPatient_name("张钧");
		record.setCure_type("内科");
		record.setDate("2014/8/9");
		record.setHospital("吕梁市中医院");
		record.setReult("胃痛");
		record.setFee("35.5");
		mRecords.add(record);
		
		 record = new CureRecord();
		record.setPatient_name("张钧");
		record.setCure_type("内科");
		record.setDate("2014/6/27");
		record.setHospital("吕梁市人民医院");
		record.setReult("流行性感冒");
		record.setFee("19");
		mRecords.add(record)
		;
		
		
	
				
		
		
		mPullListView = (PullLoadListView) findViewById(R.id.news_item_ListView);
		mPullListView.setCanRefresh(true);
		CureRecordAndHospitalAdapter adapter = new CureRecordAndHospitalAdapter(this,mRecords);
		mPullListView.setAdapter(adapter);
		System.out.println(adapter.getCount());
		mPullListView.setOnItemClickListener(OnItemClickListener);
	}
	
	private OnItemClickListener OnItemClickListener = new OnItemClickListener() {

		@Override
		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			if (--arg2 >= 0) { // -- 下拉刷新bug，少了第一条数据}
				Intent intent = null;
				Object data = mRecords.get(arg2);
				if ( data instanceof CureRecord) {
					intent = new Intent(CureRecordActivity.this,CureRecordDetailActivity.class);
					intent.putExtra(Constant.GENERAL_SAVE_KEY,(CureRecord)data);
				}else {
					intent = new Intent(CureRecordActivity.this,HospitalRecordDetailActivity.class);
					intent.putExtra(Constant.GENERAL_SAVE_KEY,(HospitalRecord)data);
				}
			startActivity(intent);
			}
		}
	};


	@Override
	protected void initialized() {
		// TODO Auto-generated method stub
		
	}



	@Override
	protected void threadTask() {
		// TODO Auto-generated method stub
		
	}
}
